//
//  NetworkManager.m
//  yameishe3
//
//  Created by pro on 2017/3/8.
//  Copyright © 2017年 yameishe. All rights reserved.
//

#import "NetworkManager.h"
#import "DataFetch.h"
#import "YMSMediaSource.h"
@implementation NetworkManager

singleton_implementation(NetworkManager)

-(void)getConditionWithDic:(NSMutableDictionary*)dic successBlock:(SuccessBlock)successBlock failureBlock:(FailureBlock)failureBlock
{
    NSString *link = [NSString stringWithFormat:@"%@set_cate",BasicUrl];
    [DataFetch postWithApi:link Dic:dic Completion:^(NSURLSessionDataTask *operation, id resultObj, NSString *link) {
        successBlock(resultObj);
    } Cache:^(id cacheObj) {
        
    } Fail:^(NSString *reason) {
        failureBlock(reason);
    }];
    
    
}
-(void)getMediaSourceWithDic:(NSMutableDictionary*)dic successBlock:(ArraySuccessBlock)successBlock failureBlock:(FailureBlock)failureBlock
{
    NSString *link = [NSString stringWithFormat:@"%@media/release",BasicUrl];
    [DataFetch postWithApi:link Dic:dic Completion:^(NSURLSessionDataTask *operation, id resultObj, NSString *link) {
        NSMutableArray *arrResult = [[NSMutableArray alloc]init];
        if ([resultObj isKindOfClass:[NSDictionary class]]) {
            NSArray *arrDict = resultObj[@"data"];
            for (NSDictionary *dict in arrDict) {
                if ([[dict allKeys] count] > 3) {
                    YMSMediaSource *model = [YMSMediaSource modelWithKeyValues:dict];
                    [arrResult addObject:model];
                }
            }
        }
        successBlock(arrResult);
    } Cache:^(id cacheObj) {
        
    } Fail:^(NSString *reason) {
        failureBlock(reason);
    }];
}
@end
